/* 
axios 网络文件
*/
import axios from 'axios'
//基本配置
const http = axios.create({
    baseURL: process.env.REACT_APP_ENV === 'production' ? process.env.REACT_APP_NETWORK : process.env.REACT_APP_BASEURL,//基本路径
    timeout: 5000
})

//请求拦截
http.interceptors.request.use((config) => {
    config.headers['Authorization'] = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MDQyNDc5MjMsIm5iZiI6MTcwNDI0NzkyMywiZXhwIjoxNzA0ODUyNzIzLCJkYXRhIjp7ImlkIjoxLCJyb2xlX2lkIjoxLCJuaWNrbmFtZSI6ImFkbWluIiwiYXZhdGFyIjoiIn19.FzIXjxIl_9DWah5YaBhqgca7H8-hjshJZRzxNgp2qJk'
    return config;
}, (error) => {
    return Promise.reject(error);
})
//响应拦截
http.interceptors.response.use((response) => {
    return Promise.resolve(response);
}, (error) => {
    return Promise.reject(error);
})

export const get = (url, params, headers) => {
    return http.get(url, {
        params: {
            _: Date.now(),
            ...params
        },
        headers
    });
}

export const post = (url, data, headers) => {
    return http.get(url, data, {
        headers
    });
}